#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<sys/wait.h>
#include<pthread.h>
#include<unistd.h>
#include<fcntl.h>
#include<arpa/inet.h>
#include<ctype.h>
#include<sys/socket.h>
//客户端
#define SERV_PORT 9527
void sys_error(const char*s){
      perror(s);
      exit(-1);
}
int main(){
   int sfd,ret;
   char buf[1024];
   sfd=socket(PF_INET,SOCK_STREAM,0);
   if(sfd==-1){
       sys_error("socket is perror");
   }
   struct sockaddr_in slientaddr;//客户端ip和端口绑定
   slientaddr.sin_family=AF_INET;
   slientaddr.sin_port=htons(SERV_PORT);
   slientaddr.sin_addr.s_addr=htonl(INADDR_ANY);
   ret=connect(sfd,(struct sockaddr*)&slientaddr,sizeof(slientaddr));
   if(ret==-1){
       sys_error("connect is perror");
   }
   while(1){
     write(sfd,"hello\n",6);
     ret=read(sfd,buf,sizeof(buf)+1);
     write(STDOUT_FILENO,buf,ret);
     sleep(1);
   }
   return 0;
}
